package example.demo.service.impl;

import example.demo.route.annotation.Route;
import example.demo.entity.User;
import example.demo.mapper.UserMapper;
import example.demo.route.aop.RouteType;
import example.demo.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xiao_rao
 * @since 2021-07-13
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    private UserMapper userMapper;

    @Route(tables = 3)
    @Override
    public User queryUserById(Integer id) {
        return this.getById(id);
    }

    @Route(tables = 3, type = RouteType.insert)
    @Override
    public void insertOne(User user) {
        this.save(user);
    }

    @Route(tables = 3, type = RouteType.delete)
    @Override
    public void deleteOne(Integer id) {
        this.removeById(id);
    }

    @Route(tables = 3, type = RouteType.update)
    @Override
    public void updateOne(User user) {
        this.updateById(user);
    }
}
